package com.njust.controller;

import com.njust.form.TableQueryByState;
import com.njust.form.TempTendencyForm;
import com.njust.service.*;
import com.njust.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;

/**
 * 数据查询
 * @author zjwpro@foxmail.com
 * @date 2018/1/9 下午10:31
 */
@RestController
@RequestMapping("/query")
@Api("查询数据模块")
public class QueryController {
    @Autowired
    private MotorService motorService;

    @Autowired
    private TablesService tablesService;

    @Autowired
    private GearService gearService;
    @Autowired
    private SystemInfoService systemInfoService ;


    @Autowired
    private TrainService trainService;

    /**
     * @param queryByState
     * @return
     */
    @PostMapping("/train")
    @ApiOperation(value="列车信息报表查询")
    public ResultVO getTrainInfos(@RequestBody TableQueryByState queryByState) throws ParseException {
        ResultVO resultVo = tablesService.getTrainInfos(queryByState);
        return resultVo;
    }

    /**
     * 列车电机的综合数据
     * @param trainOnlyid
     * @return
     */
    @GetMapping("/{trainOnlyid}/{trainDirection}/motorDetail")
    @ApiOperation(value="电机综合数据")
    public ResultVO getMotorInfos(@PathVariable("trainOnlyid") Long trainOnlyid,
                                  @PathVariable("trainDirection")Integer trainDirection) {
        return motorService.findByTrainOnlyid(trainOnlyid,trainDirection);
    }

    /**
     * 列车记录编号和电机号 返回具体齿的数据 形成报表
     * @param trainOnlyid
     * @param motorNum
     * @return
     */
    @GetMapping("/{trainOnlyid}/{trainDirection}/{motorNum}/gearDetail")
    @ApiOperation(value="齿综合数据")
    public ResultVO gearDetail(@PathVariable(name = "trainOnlyid")Long trainOnlyid,
                               @PathVariable(name = "motorNum")Integer motorNum,
                               @PathVariable("trainDirection")Integer trainDirection){
        return gearService.findByTrainOnlyidAndMotorId(trainOnlyid,motorNum,trainDirection);
    }

    /**
     * 返回左右激光原始数据
     * @param trainOnlyid 列车记录编号
     * @param motorNum 电机编号（1-8）
     * @return
     */
    @GetMapping("/{trainOnlyid}/{trainDirection}/{motorNum}/laser")
    @ApiOperation(value="激光原始数据")
    public ResultVO laserData(@PathVariable(name = "trainOnlyid")Long trainOnlyid,
                              @PathVariable(name = "motorNum") Integer motorNum,
                              @PathVariable("trainDirection")Integer trainDirection){
        return motorService.findByTrainOnlyidAndMotorNum(trainOnlyid,motorNum,trainDirection);
    }

    @ApiOperation(value="激光传感器与温度传感器状态")
    @RequestMapping("/systemInfo")
    public ResultVO systemInfoLast() {
     return systemInfoService.querySystemInfo();
    }


/**
 * 新添加的历史温度查询,通过列车号，电机号、时间进行查询
 */

@ApiOperation(value = "历史温度趋势查询")
    @RequestMapping("/tempTendency")
    public ResultVO tempTendencyQueru(@RequestBody TempTendencyForm tempTendencyForm) throws ParseException {
    //进行相应的数据查询
    return motorService.findTempTendency(tempTendencyForm);

}
}
